<?php

namespace app\libs\DianDianPaySDK;

use app\libs\HttpSDK\HttpService;
use app\model\ShopsPayment;
use Carbon\Carbon;
use think\helper\Arr;


class DianDianPayClient extends HttpService
{
    protected string $timestamp;
    protected string $timezone = "Asia/Shanghai";
    protected string $merchant_id;
    protected string $private_key;
    const SANDBOX_ENV_HOST = "https://test-api.diandianpay.com";
    const LIVE_ENV_HOST = "https://api.diandianpay.com";
    public function __construct(ShopsPayment $payment)
    {

        $this->timestamp = strval(Carbon::now()->getTimestampMs());
        $config = $payment->config;
        $this->merchant_id = Arr::get($config,'merchant_no');
        $env = Arr::get($config,'env');
        $pemPath = sprintf("pem/%s/%s/private_key.pem",$env,$this->merchant_id);
        $this->private_key = file_get_contents(public_path().'/'.$pemPath);
        $base_uri = $payment->mode == ShopsPayment::MODE_SANDBOX ? self::SANDBOX_ENV_HOST : self::LIVE_ENV_HOST;
        $this->setBaseUrl($base_uri)
            ->setChannel("diandianpay");
    }



}